package com.ali.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Collection;

/**
 * 根目录导航
 */
@Slf4j
@Controller
public class IndexController {
    @GetMapping("/")
    public String index() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();
        //获取用户信息
        Object principal = authentication.getPrincipal();
        //获取用户认证信息
        Object credentials = authentication.getCredentials();
        //获取用户权限信息
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        log.info("principal：" + principal);
        log.info("credentials：" + credentials);
        log.info("authorities：" + authorities);
        return "index";
    }
}